<?include ($_SERVER ["DOCUMENT_ROOT"] . "/lib/module/conn_db.php");?>
<?include ($_SERVER ["DOCUMENT_ROOT"] . "/lib/module/Util.php");?>
<?php //DB Open

	$result = null;
	$db = new MyDB ( false );
	$db->err_report = true;

?>
<?php

	$util = new Util();

	$page = $_GET ["page"];

	if (!$page)	$page = 1;

	$pern = 8;
	$perb = 10;

	$condition = $_GET ["condition"];
	$words = $_GET ["words"];

	if($condition!="" && $words!=""){
		$search .= " and ".$condition." LIKE '%".$words."%'";
	}

	$sid = $_GET['sid'];

	$addStr = "sid=".$sid;

	$sql = "SELECT * from tb_board_article WHERE category_sid=".$sid." and board_sid=3".$search." ORDER BY article_sid DESC";
	$db->query ( $sql );
	$query = $db->result;
	$total = mysql_num_rows ($query);

	if ($total > 0) {

		$lastpage = ceil( $total / $pern );
		if ( $page > $lastpage ) $page = $lastpage;
		$first = ( $page - 1 ) * $pern;

		// 페이징 목록
		$lastbl = ceil ( $lastpage / $perb );
		$bl = ceil ( $page / $perb );
		$stpage = ($bl - 1) * $perb + 1;
		$edpage = ($bl - 1) * $perb + $perb;
		// 글번호
		$start_no = $total - (($page - 1) * $pern);

		$sql .= " limit $first, $pern ";


		$db->query ( $sql );
		$result = $db->result;
	}
	$i=0;
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<? include "inc/inc_header.php" ?><!-- header -->
 <body style="background-color:transparent" oncontextmenu="return false" onselectstart="return false" ondragstart="return false">
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
	  <tr>
		<td align="right" style="padding-bottom:10px;">
		<form name="frm" method="get" action="<?=$pageUrl?>">
		<table width="0" border="0" cellspacing="0" cellpadding="0">
			<tr>
			  <td style="padding-right:4px"> <select name="condition" id="condition"  class="box01">
				  <option value="article_title" <?=$condition=="article_title" ? "selected" : "" ?>>제목</option>
				  <option value="article_contents1" <?=$condition=="article_contents1" ? "selected" : "" ?>>내용</option>
			  </select></td>
			  <td style="padding-right:4px">
			  <input type="hidden" name="sid" value="<?=$sid?>"/>
			  <input type="hidden" name="page" value="<?=$page?>"/>
			  <input type="text" name="words" title="검색어" class="box01" size="35" value="<?=$words?>" /></td>
			  <td><input type="image" src="img/board/btn_search.gif" alt="검색하기" style="width:50px;height:20px;"/></td>
			</tr>
		</table>
		</form>
		</td>
	  </tr>
	  <tr>
		<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td>
			  <?php if($total>0):?>
				<?php while($row = mysql_fetch_object($result)):?>
				  <?php if($i%4==0):?>
					<table width="100%" border="0" cellspacing="0" cellpadding="0">
					  <tr>
				  <?php endif;?>
						 <td <?php if($i%4!=3):?>width="248"<?php endif;?> valign="top" style="padding-bottom:30px;"><table width="210" border="0" cellspacing="0" cellpadding="0">
							  <tr>
								<td><a href="surn01_01_2_v.php?sid=<?php echo $sid;?>&art_sid=<?php echo $row->article_sid;?>&page=<?php echo $page;?>">
								<?php
									$sql = "SELECT file_name from tb_board_file WHERE article_sid=".$row->article_sid." ORDER BY file_sid DESC limit 0,1;";
									$db->query ( $sql );
									$file = mysql_fetch_object($db->result);
								?>
									<img src="uploads/3/<?php echo $file->file_name;?>" width="206" height="136" border="0">
								</a></td>
							  </tr>
							  <tr>
								<td align="center" class="text02" style="padding-top:8px;"><strong><?php echo $row->article_title;?></strong></td>
							  </tr>
						  </table></td>
				  <?php if ($i+1==$total%8 && $lastpage==$page) :?>
					<?php $q = $i%4+1;;?>
					<?php for ($j=0; $j<3-($i%4); $j++) :?>
						<td <?php if($q%4!=3):?>width="248"<?php endif;?> class="text02">&nbsp;</td>
						<?php $q++;?>
					<?php endfor;?>
				  <?php endif;?>
				  <?php if($i%4==3 || ($q-1)%4==3):?>
					  </tr>
					</table>
				  <?php endif;?>
				  <?php $i++;?>
				<?php endwhile;?>
			  <?php endif;?>
		</td>
	  </tr>
	  <tr>
		<td align="center">
			<?php if ($total > 0) : ?>
				<table cellspacing="0" cellpadding="0">
				  <tr>
					<td width="20">
					  <?php if($stpage-10>0): ?>
					    <a href="<?=$_SERVER["PHP_SELF"]?>?page=<?=$stpage-10?>&amp;<?=$addStr?>">
					      <img height="7" src="img/board/btn_prev_01.gif" width="9" align="absmiddle" border="0" />
						</a>
					  <?php endif;?>
					</td>
					<td width="20">
					  <a href="<?=$_SERVER["PHP_SELF"]?>?page=1&amp;<?=$addStr?>">
					    <img height="7" src="img/board/btn_prev_02.gif" width="5" align="absmiddle" border="0" />
					  </a>
					</td>
					<td align="middle" class="dbpaging">
					<?
						for($i=$stpage; ($i<=$edpage && $i<=$lastpage); $i++) {
							if($i<0)
							{
								continue;
							}
							if($i==$page)
							{
								echo "<a href='".$_SERVER['PHP_SELF']."?page=$i&amp;$addStr'><span class='dbbold'>".$i."</span></a>";
							}else{
								echo "<a href='".$_SERVER['PHP_SELF']."?page=$i&amp;$addStr' class='dblink'>".$i."</a>";
							}
						}
					?>
					</td>
					<td width="20" align="right">
					  <a href="<?=$_SERVER["PHP_SELF"]?>?page=<?=$lastpage?>&amp;<?=$addStr?>">
						<img src="img/board/btn_next_02.gif" width="5" height="7" border="0" align="absmiddle" />
					  </a>
					</td>
					<td width="20" align="right">
					  <?php if ($edpage < $lastpage):?>
					    <a href="<?=$_SERVER["PHP_SELF"]?>?page=<?=$stpage+10?>&amp;<?=$addStr?>">
						  <img height="7" src="img/board/btn_next_01.gif" width="9" align="absmiddle" border="0" />
					    </a>
					  <?php endif;?>
				   <?php endif;?>
				</td>
			</tr>
		</table></td>
	  </tr>
	</table>
 </body>
</html>
<?php //DB Close

	$db->close ();

?>